<?php include '../init.php';
	print_r($_POST);
?>
<!DOCTYPE html>
<html>
<head>
	<title>添加文章</title>
	<link rel="stylesheet" type="text/css" href="<?php echo __PUBLIC__;?>/bootsrap/css/bootstrap.min.css">
	<link rel="stylesheet" type="text/css" href="<?php echo __PUBLIC__;?>/webupload/webuploader.css">
	<script type="text/javascript" src="<?php echo __PUBLIC__;?>/js/jquery.js"></script>
	<script type="text/javascript" src="<?php echo __PUBLIC__;?>/bootsrap/js/bootstrap.min.js"></script>
	<script type="text/javascript" src="<?php echo __PUBLIC__;?>/validate/jquery.validate.min.js"></script>
	<script type="text/javascript" src="<?php echo __PUBLIC__;?>/validate/localization/messages_zh.min.js"></script>
	<script type="text/javascript" src="<?php echo __PUBLIC__;?>/webupload/webuploader.js"></script>
	<script type="text/javascript" src="<?php echo __PLUGIN__;?>/ueditor/ueditor.config.js"></script>
	<script type="text/javascript" src="<?php echo __PLUGIN__;?>/ueditor/ueditor.all.js"></script>
</head>
<body>
	<div class="container">
		<div class="row">
			<?php include '../nav.php';?>
		</div>
	</div>
	<div class="container">
		<div class="row">
			<div class="col-md-12">
				<form action="form.php" id="articleForm" method="post">
					<div class="form-group">
						<label for="title">标题</label>
						<input type="text" class="form-control" name="title" id="title" placeholder="标题" required="true">
					</div>
					<div class="form-group">
						<label for="author">作者</label>
						<input type="text" class="form-control" name="author" id="author" placeholder="作者" required="true">
					</div>
					<div class="form-group">
						<label for="img">封面图片</label>
						<div class="row">
							<div id="picker" class="col-md-2">上传</div>
							<div id="picbox" class="col-md-3"></div>
						</div>
						<input type="hidden" id="img" name="img" placeholder="封面图片">
					</div>
					<div class="form-group">
						<label for="keyword">关键词</label>
						<input type="text" class="form-control" name="keyword" id="keyword" placeholder="关键词" required="true">
					</div>
					<div class="form-group">
						<label for="description">描述</label>
						<input type="text" class="form-control" name="description" id="description" placeholder="描述" required="true">
					</div>
					<div class="form-group">
						<label for="status">状态</label>
						<select name="status">
							<option value="1">打开</option>
							<option value="0">关闭</option>
						</select>
					</div>
					<div class="form-group">
						<label for="content">内容</label>
						<textarea name="content" id="content"></textarea>
					</div>
					<div class="form-group">
						<button class="btn btn-primary">保存</button>
					</div>
				</form>
				<div class="modal fade bs-example-modal-sm" id="myModal" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel">
				    <div class="modal-dialog modal-sm" role="document">
				      <div class="modal-content">

				        <div class="modal-header">
				          <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
				          <h4 class="modal-title" id="mySmallModalLabel">Small modal</h4>
				        </div>
				        <div class="modal-body">
				          ...
				        </div>
				      </div><!-- /.modal-content -->
				    </div><!-- /.modal-dialog -->
				  </div>
				<script type="text/javascript">
					 var ue = UE.getEditor('content',{
			        	initialFrameWidth:600,
			        	initialFrameHeight:400,
			        	autoHeightEnabled:false,
			        });
				</script>
				<script type="text/javascript">
					$('#articleForm').on('submit',function(){
						$.ajax({
							type:'post',
							url:$('#articleForm').attr('action'),
							data:$('#articleForm').serialize(),
							dataType:'json',
							success:function(data){
								if(data.code=='000'){
									window.location="<?php echo $config['local'];?>/admin/article/index.php"
								}else{
									$('#myModal .modal-body').html(data.msg);
									$('#myModal').modal({'show':true});
								}
							}
						});
						return false;
					});
				</script>
				<script type="text/javascript">
					var uploader = WebUploader.create({
						// 选完文件后，是否自动上传。
			    		auto: true,
					    // swf文件路径
					    swf: '<?php echo __PUBLIC__;?>/webupload/Uploader.swf',
					    // 文件接收服务端。
					    server: '<?php echo $config['local'];?>/lib/upfile.php',
					    // 选择文件的按钮。可选。
					    // 内部根据当前运行是创建，可能是input元素，也可能是flash.
					    pick: '#picker',
					    // 不压缩image, 默认如果是jpeg，文件上传前会压缩一把再上传！
					    resize: false,

					    runtimeOrder:false,
					    // 只允许选择图片文件。
					    accept: {
					        title: 'Images',
					        extensions: 'gif,jpg,jpeg,bmp,png',
					        mimeTypes: 'image/jpg,image/jpeg,image/png',
					    }
					});
					uploader.on( 'fileQueued', function( file ) {
					    var $li = $(
			            '<div id="' + file.id + '" class="file-item thumbnail">' +
			                '<img>' +
			                '<div class="info">' + file.name + '</div>' +
			            '</div>'
			            ),
			        	$img = $li.find('img');
			        	$('#picbox').html( $li );
			        	uploader.makeThumb( file, function( error, src ) {
					        if ( error ) {
					            $img.replaceWith('<span>不能预览</span>');
					            return;
					        }

					        $img.attr( 'src', src );
					    }, 100, 100 );
					});
				    uploader.on( 'uploadSuccess', function(file,response) {
					    $('#img').val(response._raw);
					});
					uploader.on( 'uploadError', function( file ) {
					    var $li = $( '#'+file.id ),
					        $error = $li.find('div.error');

					    // 避免重复创建
					    if ( !$error.length ) {
					        $error = $('<div class="error"></div>').appendTo( $li );
					    }

					    $error.text('上传失败');
					});
				</script>
			</div>
		</div>
	</div>
</body>
</html>